#!/bin/bash

# 检查参数
if [ "$#" -ne 1 ]; then
    echo "Usage: $0 <env>"
    echo "Example: $0 prod"
    exit 1
fi

ENV=$1
CONFIG_FILE="config/config.${ENV}.yaml"

# 检查配置文件是否存在
if [ ! -f "$CONFIG_FILE" ]; then
    echo "Config file not found: $CONFIG_FILE"
    exit 1
fi

# 停止并删除旧容器
echo "Stopping old containers..."
docker-compose down

# 构建新镜像
echo "Building new images..."
docker-compose build --no-cache

# 启动新容器
echo "Starting new containers..."
docker-compose up -d

# 检查服务状态
echo "Checking service status..."
docker-compose ps

# 检查日志
echo "Checking logs..."
docker-compose logs --tail=100 